#!/usr/bin/env bash

build_cunumeric_wheel() {
    set -xeuo pipefail;

    mkdir -p /tmp/out;

    local pip_args=(-vv);
    pip_args+=(--wheel-dir /tmp/out);

    if type conda 2>&1 >/dev/null; then
        pip_args+=(--no-deps);
        pip_args+=(--no-build-isolation);
    fi

    local cmake_args=(${CMAKE_ARGS:-});
    cmake_args+=("-DFIND_CUNUMERIC_CPP=ON");
    cmake_args+=("-Dcunumeric_ROOT=$HOME/cunumeric/build");

    # Build + package cuNumeric Python wheel
    CMAKE_ARGS="${cmake_args[@]}" \
        pip wheel ${pip_args[@]} ~/cunumeric;

    { set +x; } 2>/dev/null;
}

(build_cunumeric_wheel "$@");
